package com.lagou.homework;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/*
 * @className NumSortReducer
 * @description 接收map端输入的数据，数据已经经过进行排序了
 * @author admin
 * @date 2022/5/15 22:55
 * */
// 第一对kv:IntWritable，IntWritable为map的输出
public class NumSortReducer extends Reducer<IntWritable, IntWritable, IntWritable,IntWritable> {
    // 行号
    private IntWritable line = new IntWritable(1);

    @Override
    protected void reduce(IntWritable key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        // values为一组key相同的kv组成的集合
        // 1.遍历values集合
        for (IntWritable value : values) {
            // 2.输出kv
            context.write(line, key);
            // 3.每一次输出行号自增
            line.set(line.get()+1);
        }
    }
}
